﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InitPayInfoForm.aspx.cs"
    Inherits="PSS.WebSite.FundManage.InitPayInfoForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="../lib/boot.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" method="post">
    <input name="InitPayId" class="mini-hidden" />
    <fieldset style="border: solid 1px #aaa; padding: 5px;">
        <legend>单据信息</legend>
        <table align="left" style="table-layout: fixed; width: 100%;">
            <tr>
                <td style="width: 80px;" align="right">
                    购货单位：
                </td>
                <td style="width: 150px;" align="left">
                    <div id="VendorId" name="VendorId" class="mini-combobox" style="width: 150px;" popupwidth="250px"
                        required="true" textfield="VendorName" valuefield="VendorId">
                        <div property="columns">
                            <div header="购货单位编号" field="VendorCode" width="40%">
                            </div>
                            <div header="购货单位名称" field="VendorName" width="60%">
                            </div>
                        </div>
                    </div>
                </td>
                <td style="width: 80px;" align="right">
                    单据日期：
                </td>
                <td style="width: 150px;" align="left">
                    <input name="SinglePaymentDate" style="width: 150px;" class="mini-datepicker" format="yyyy-MM-dd"
                        required="true" />
                </td>
                <td style="width: 80px;" align="right">
                    单据编号：
                </td>
                <td style="width: 150px;" align="left">
                    <span id="SinglePaymentNo" name="SinglePaymentNo"></span>
                </td>
            </tr>
        </table>
    </fieldset>
    <fieldset style="border: solid 1px #aaa; padding: 3px; height: 300px;">
        <legend>账户列表</legend>
        <div class="mini-toolbar" style="padding: 2px; border-bottom: 0;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="addRow();" plain="true">添加</a>
                        <a class="mini-button" iconcls="icon-remove" onclick="removeRow()" plain="true">删除</a>
                    </td>
                </tr>
            </table>
        </div>
        <!--撑满页面-->
        <div class="mini-fit">
            <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" idfield="PayDetailId"
                allowcelledit="true" allowcellselect="true" showfooter="false" multiselect="true"
                allowsortcolumn="false">
                <div property="columns">
                    <div type="checkcolumn">
                    </div>
                    <div field="AccountId" name="AccountId" width="90" displayfield="AccountName" headeralign="center"
                        allowsort="false">
                        结算账户
                        <input property="editor" class="mini-combobox" style="width: 100%;" valuefield="AccountId"
                            textfield="AccountName" url="../../Service/SetManageHandler.ashx?action=GetAccountListByCombobox" />
                    </div>
                    <div field="PayMoney" width="90" headeralign="center" allowsort="false">
                        付款金额
                        <input property="editor" class="mini-spinner" minvalue="0" maxvalue="999999999" decimalplaces="4"
                            style="width: 100%;" />
                    </div>
                    <div field="SCategoryId" width="100" displayfield="SCategoryName" headeralign="center"
                        allowsort="false">
                        结算方式
                        <input property="editor" class="mini-combobox" style="width: 100%;" valuefield="SCategoryId"
                            textfield="SCategoryName" url="../../Service/SetManageHandler.ashx?action=GetSettlementCategoryListByCombobox" />
                    </div>
                    <div field="SettleNo" name="SettleNo" width="80" headeralign="center" allowsort="false">
                        结算号
                        <input property="editor" class="mini-textbox" style="width: 100%;" />
                    </div>
                    <div field="Remark" width="90" headeralign="center" allowsort="false">
                        备注
                        <input property="editor" class="mini-textarea" style="width: 100%;" />
                    </div>
                </div>
            </div>
        </div>
    </fieldset>
    <table style="width: 100%;">
        <tr>
            <td style="width: 12%;" align="right">
                备注：
            </td>
            <td style="width: 88%" align="left" colspan="5">
                <input name="Remark" class="mini-textarea" style="width: 100%; height: 50px;" />
            </td>
        </tr>
    </table>
    <div style="text-align: center; padding: 10px;">
        <a class="mini-button" iconcls="icon-save" onclick="onOk" style="width: 60px; margin-right: 20px;">
            保存</a> <a class="mini-button" iconcls="icon-cancel" onclick="onCancel" style="width: 60px;">
                取消</a>
    </div>
    </form>
    <script type="text/javascript">
        mini.parse();
        var VendorId = mini.getbyName("VendorId");
        VendorId.setUrl("../Service/SetManageHandler.ashx?action=GetVendorListByCombobox");
        var action;
        var grid = mini.get("datagrid1");
        var form = new mini.Form("form1");
        function addRow() {
            var newRow = { name: "New Row" };
            grid.addRow(newRow, 0);
            grid.beginEditCell(newRow, "AccountId");
        }
        function removeRow() {
            var rows = grid.getSelecteds();
            if (rows.length > 0) {
                grid.removeRows(rows, true);
            }
        }
        function SaveData() {
            var data = grid.getData();
            var o = form.getData();
            o.SinglePaymentNo = $("#SinglePaymentNo")[0].innerHTML;
            form.validate();
            if (form.isValid() == false) return;
            if (data.length > 0) {
                var AccountIdCount = 0;
                var PayMoneyCount = 0;
                var SCategoryIdCount = 0;
                for (var i = 0; i < data.length; i++) {
                    if (data[i].AccountId == undefined) {
                        AccountIdCount = AccountIdCount + 1;
                    }
                    if (data[i].PayMoney == undefined) {
                        PayMoneyCount = PayMoneyCount + 1;
                    }
                    if (data[i].SCategoryId == undefined) {
                        SCategoryIdCount = SCategoryIdCount + 1;
                    }
                }
                if (AccountIdCount > 0) {
                    mini.alert("结算账户不能为空，请重新选择...");
                    return;
                }
                if (PayMoneyCount > 0) {
                    mini.alert("付款金额不能为空，请重新选择...");
                    return;
                }
                if (SCategoryIdCount > 0) {
                    mini.alert("结算方式不能为空，请重新选择...");
                    return;
                }
                saveData(o, data);
            }
            else {
                mini.alert("账户列表不能为空！");
            }
        }
        function saveData(o, data) {
            o.arrList = data;
            var json = mini.encode([o]);
            if (viewaction == "edit") {
                $.ajax({
                    url: "../Service/FundManageHandler.ashx?action=ModifyInitPay",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            else {
                $.ajax({
                    url: "../Service/FundManageHandler.ashx?action=AddInitPay",
                    data: { data: json },
                    type: 'POST',
                    success: function (text) {
                        CloseWindow("save");
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }

        function SetData(data) {
            viewaction = data.action;
            data = mini.clone(data);
            if (data.action == "edit") {
                $.ajax({
                    url: "../service/FundManageHandler.ashx?action=GetInitPayInfo&InitPayId=" + data.InitPayId,
                    cache: false,
                    success: function (text) {
                        var o = mini.decode(text);
                        form.setData(o);
                        form.setChanged(false);
                        $("#SinglePaymentNo").text(o.SinglePaymentNo);
                        $.ajax({
                            url: "../service/FundManageHandler.ashx?action=GetInitPayDetailList&InitPayId=" + data.InitPayId,
                            cache: false,
                            success: function (text) {
                                var o = mini.decode(text);
                                grid.setData(o);
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert(jqXHR.responseText);
                            }
                        });
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
            else {
                mini.getbyName("SinglePaymentDate").setValue(new Date().format("yyyy-MM-dd"));
                $.ajax({
                    url: "../service/CommonManageHandler.ashx?action=GetSinglePaymentNo",
                    success: function (text) {
                        $("#SinglePaymentNo").text(text);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        alert(jqXHR.responseText);
                    }
                });
            }
        }
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (action == "close" && form.isChanged()) {
                if (confirm("数据被修改了，是否先保存？")) {
                    return false;
                }
            }
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }

        function onOk() {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
</body>
</html>
